package net.daoke.relation.repository;

import net.daoke.relation.model.domain.NodeDomain;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface NodeRepository extends Neo4jRepository<NodeDomain, Long> {

    /**
     * 根据IP查询主机
     * @param ip
     * @return
     */
    @Query("MATCH (n:Node) WHERE $ip IN n.ips RETURN n")
    Optional<NodeDomain> getOneByIp(String ip);


    @Query("MATCH (n:Node) WHERE n.no = $no RETURN n")
    Optional<NodeDomain> getNodeDomainByNo(String no);
}